package com.yyj.config;

import com.github.wxpay.sdk.WXPayConfig;
import com.yyj.common.ConfigReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @author leezp
 * @create 2018-04-10 14:15
 **/
@Component
public class WeixinPayConfig implements WXPayConfig {

    @Autowired
    ConfigReader configReader;

    @Override
    public String getAppID() {
        return configReader.getAppId();
    }

    @Override
    public String getMchID() {
        return configReader.getMchId();
    }

    @Override
    public String getKey() {
        return configReader.getPayKey();
    }

    @Override
    public InputStream getCertStream() {
        try {
            return new FileInputStream(configReader.getCertFile());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
